<?php
class Nadeb_Form_Captcha
{
	private $param;
	private $name;
	
	private $inputTag;
	private $tag = "";
	
	public function __construct($_param)
	{
		$this->param   = $_param;
	}
	
	public function create_object()
	{
		$file       = new Nadeb_Form_Captcha_File();
		$this->name = $file->get( $this->param['background'], $this->param['font'] );
		
		/*
		 * dt TAG
		 */
		$this->tag .= "
		<dt id=\"{$this->param["id"]}-label\">
			<label for=\"captcha\" class=\"{$this->param["name"]}-label\">{$this->param["label"]}</label>
		</dt>";

		/*
		 * dd TAG
		 */
		$this->tag .= "
		<dd id=\"{$this->param["id"]}-object\">
			<div>
				<span><img src=\"". ROOT ."/public/captcha/temps/{$this->name}.png\" class=\"captcha-image\" /></span>
				<span><a href=\"#reloadCaptcha\" class=\"captcha-link\">Recarregar</a></span>
				<script>
				$(document).ready(function()
				{
					$('a[href=#reloadCaptcha]').click(function()
					{
						$.get('/index/recaptcha/bg/{$this->param['background']}/font/{$this->param['font']}',function(file)
						{
							$('.captcha-image').attr('src','/public/captcha/temps/'+file+'.png');
						});
						
						return false;
					})
				})
				</script>
			</div>
			<input name=\"captcha\" id=\"captcha\" type=\"text\" class=\"captcha\" />
		</dd>";
	}
	
	public function get_xhtml()
	{
		return $this->tag;
	}
}
